package com.chuanwei.controller;

import com.chuanwei.pojo.Emp;
import com.chuanwei.pojo.LoginInfo;
import com.chuanwei.pojo.Result;
import com.chuanwei.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private EmpService empService;

    /**
     * 员工登录
     * @param emp
     * @return
     */
    @PostMapping()
    public Result login(@RequestBody Emp emp ){
        log.info("登录：{}",emp);
        LoginInfo info =empService.login(emp);
        if (info != null){
            return Result.success(info);
        }
        return Result.error("用户名或者密码错误");
    }
}
